package com.css.fxfzypg.modules.saresults.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.style.StyleUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.constants.FxfzConstants;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.saresults.entity.*;
import com.css.fxfzypg.modules.saresults.entity.jcsj.*;
import com.css.fxfzypg.modules.saresults.param.DrillHoleQueryParam;
import com.css.fxfzypg.modules.saresults.repository.DrillHoleQueryRepository;
import com.css.fxfzypg.modules.saresults.repository.SaResultsRepository;
import com.css.fxfzypg.modules.saresults.service.DrillHoleQueryService;
import com.css.fxfzypg.modules.saresults.vo.DrillHoleQueryVo;
import com.css.fxfzypg.modules.saresults.vo.DrillHoleVo;
import com.css.fxfzypg.modules.saresults.vo.JcRfcpDrillDetailVo;
import com.css.fxfzypg.util.*;
import com.css.fxfzypg.web.PlatformSessionContext;
import com.css.fxfzypg.zcpt.sys.entity.SUser;
import com.css.fxfzypg.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.slw.common.helper.PropsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class DrillHoleQueryServiceImpl implements DrillHoleQueryService {

    @Autowired
    private DrillHoleQueryRepository drillHoleQueryRepository;

    @Autowired
    private SaResultsRepository saResultsRepository;

    @Resource
    private RestTemplateUtil restTemplateUtil;

    @Autowired
    private SysRoleService roleService;


    Properties configGroup = PropsHelper.loadProps("slw-config.properties");
    String url = configGroup.getProperty("restTemplateUrl") + "/datacenter/jcRfcpDrill/getById";

    @Override
    public RestResponse queryData(DrillHoleQueryParam param, HttpServletRequest request,String geom) {
        try {
            int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String role = roleService.getRoleByUserId(PlatformSessionContext.getUserID());
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            return RestResponse.succeed(drillHoleQueryRepository.queryData(param, page, size,roleList,geom));
        } catch (NumberFormatException e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse queryMapData(DrillHoleQueryParam param, HttpServletRequest request) {
        try {
            String role = roleService.getRoleByUserId(PlatformSessionContext.getUserID());
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            return RestResponse.succeed(drillHoleQueryRepository.queryMapData(param, roleList));
        } catch (NumberFormatException e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse getById(String id, String type) {
        try {
            return RestResponse.succeed(getDataById(id, type));
        } catch (Exception e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }


    private DrillHoleVo getDataById(String id, String type) {
        DrillHoleVo resultVo = new DrillHoleVo();
        if (type.equals(FxfzConstants.DZQH_JCSJ_MODEL)) {
            DzqhApCruxLayerPfEntity pfEntity = new DzqhApCruxLayerPfEntity();
            DzqhApCruxScEntity scEntity = new DzqhApCruxScEntity();
            //土动力
            List<DzqhApCruxSdEntity> sdList = new ArrayList<>();
            List<DzqhApCruxDhEntity> dhList = new ArrayList<>();
            HashMap<String, Object> paramMap = new HashMap<>();
            paramMap.put("id", id);
            ResponseEntity<String> result = restTemplateUtil.sendHttpRequestPj(url, paramMap);
            JSONObject json = JSONObject.parseObject(result.getBody());
            String data = json.getString("data");
            if (StringUtils.isNotBlank(data)) {
                List<JcRfcpDrillDetailVo> vo = JSONArray.parseArray("[" + data + "]", JcRfcpDrillDetailVo.class);
                vo.forEach(it -> {
                    JcRfcpY02 jcRfcpY02 = it.getJcRfcpY02();
                    pfEntity.setProjectName(jcRfcpY02.getDrillDependProject());
                    pfEntity.setBoreholeNumber(jcRfcpY02.getDrillCode());
                    pfEntity.setHlLongitude(jcRfcpY02.getLongitude().toString());
                    pfEntity.setHlLatitude(jcRfcpY02.getLatitude().toString());
                    pfEntity.setDrillingDepth(jcRfcpY02.getDrillDepth());
                    pfEntity.setGroundElevation(jcRfcpY02.getElevation());
                    pfEntity.setGroundwaterLevel(jcRfcpY02.getStableWaterDepth());
                    resultVo.setPfEntity(pfEntity);
                    //土动力参数
                    List<JcRfcpY08> jcRfcpY08 = it.getJcRfcpY08();
                    List<JcRfcpY06> jcRfcpY06 = it.getJcRfcpY06();
                    JcRfcpY09 jcRfcpY09 = it.getJcRfcpY09();
                    JcRfcpY18 jcRfcpY18 = it.getJcRfcpY18();

                    List<JcRfcpY15> jcRfcpY15 = it.getJcRfcpY15();

                    double shearWaveVelocityValue = getShearWaveVelocityValue(jcRfcpY15);
                    double eswv = getEswvValue(jcRfcpY06, shearWaveVelocityValue);
                    //钻孔计算模型
                    jcRfcpY06.forEach(jcRfcpY061 -> {
                        jcRfcpY08.forEach(jc -> {
                            DzqhApCruxSdEntity sdEntity = new DzqhApCruxSdEntity();
                            sdEntity.setStNumber(jc.getCode().toString());
                            sdEntity.setGeotechnicalName(jcRfcpY061.getGeotechnicalDesignation());
                            sdEntity.setBoreholeNumber(jcRfcpY02.getDrillCode());
                            sdEntity.setBdosSample(jc.getSpecimenStartDepth().toString());
                            sdEntity.setParameterSource(jcRfcpY09.getDataSources());
                            sdEntity.setSdDensity(jc.getNaturalDensity().toString());
                            sdEntity.setModulusRatio1(jc.getModulusShearStrain005());
                            sdEntity.setModulusRatio2(jc.getModulusShearStrain010());
                            sdEntity.setModulusRatio3(jc.getModulusShearStrain050());
                            sdEntity.setModulusRatio4(jc.getModulusShearStrain100());
                            sdEntity.setModulusRatio5(jc.getModulusShearStrain500());
                            sdEntity.setModulusRatio6(jc.getModulusShearStrain1000());
                            sdEntity.setModulusRatio7(jc.getModulusShearStrain5000());
                            sdEntity.setModulusRatio8(jc.getModulusShearStrain10000());
                            sdEntity.setDampingRatio1(jc.getDampShearStrain005());
                            sdEntity.setDampingRatio2(jc.getDampShearStrain010());
                            sdEntity.setDampingRatio3(jc.getDampShearStrain050());
                            sdEntity.setDampingRatio4(jc.getDampShearStrain100());
                            sdEntity.setDampingRatio5(jc.getDampShearStrain500());
                            sdEntity.setDampingRatio6(jc.getDampShearStrain1000());
                            sdEntity.setDampingRatio7(jc.getDampShearStrain5000());
                            sdEntity.setDampingRatio8(jc.getDampShearStrain10000());
                            sdList.add(sdEntity);

                            DzqhApCruxDhEntity cruxDhEntity = new DzqhApCruxDhEntity();
                            cruxDhEntity.setGeotechnicalName(jcRfcpY061.getGeotechnicalDesignation());
                            cruxDhEntity.setStNumber(jc.getCode().toString());
                            cruxDhEntity.setLbDepth(jcRfcpY061.getBottomDepth());
                            cruxDhEntity.setGeotechnicalDensity(jc.getNaturalDensity());
                            cruxDhEntity.setLayerThickness(jcRfcpY061.getLayerThickness());
                            cruxDhEntity.setSwVelocity(jcRfcpY061.getShearWaveVelocity());
                            dhList.add(cruxDhEntity);

                            scEntity.setBoreholeNumber(jcRfcpY02.getDrillCode());
                            scEntity.setEswv(eswv);
                            scEntity.setTocLayer(shearWaveVelocityValue);
                            scEntity.setFieldType(jcRfcpY18.getSiteType());
                            resultVo.setScEntity(scEntity);
                        });
                    });
                });
                resultVo.setSdList(sdList);
                resultVo.setDhList(dhList);
                resultVo.setPfEntity(pfEntity);
                resultVo.setScEntity(scEntity);
            }

        } else if (type.equals(FxfzConstants.DZQH_PCSJ_MODEL)) {
            //成孔
            DzqhApCruxLayerPfEntity pfEntity = drillHoleQueryRepository.getPfEntityById(id).get(0);
            //场地类别
            if (PlatformObjectUtils.isNotEmpty(pfEntity)) {
                DzqhApCruxScEntity scEntity = drillHoleQueryRepository.getScEntityByNumber(pfEntity.getBoreholeNumber(), pfEntity.getPfId());
                if (PlatformObjectUtils.isNotEmpty(scEntity)) {
                    resultVo.setScEntity(scEntity);
                }
                //土动力
                List<DzqhApCruxSdEntity> sdList = drillHoleQueryRepository.getSdListByNumber(pfEntity.getBoreholeNumber(), pfEntity.getPfId());
                //钻孔计算
                ArrayList<DzqhApCruxDhEntity> dhList = new ArrayList<>();
                sdList.forEach(it -> {
                    DzqhApCruxDhEntity dhListByCode = drillHoleQueryRepository.getDhListByCode(it.getStNumber(), it.getPfId());
                    if (PlatformObjectUtils.isNotEmpty(dhListByCode)) {
                        dhList.add(dhListByCode);
                    }
                });
                resultVo.setSdList(sdList);
                resultVo.setDhList(dhList);
                resultVo.setPfEntity(pfEntity);
            }
        } else {
            //成孔
            DzqhApCruxLayerPfEntity pfEntity = drillHoleQueryRepository.getPfEntityById(id).get(0);
            //场地类别
            if (PlatformObjectUtils.isNotEmpty(pfEntity)) {
                DzqhApCruxScEntity scEntity = drillHoleQueryRepository.getScEntityByProjectId(pfEntity.getProjectId(), pfEntity.getBoreholeNumber());
                if (PlatformObjectUtils.isNotEmpty(scEntity)) {
                    resultVo.setScEntity(scEntity);
                }
                //土动力
                List<DzqhApCruxSdEntity> sdList = drillHoleQueryRepository.getSdListByProjectId(pfEntity.getProjectId(), pfEntity.getBoreholeNumber());
                //钻孔计算
                ArrayList<DzqhApCruxDhEntity> dhList = new ArrayList<>();
                sdList.forEach(it -> {
                    DzqhApCruxDhEntity dhListByProjectId = drillHoleQueryRepository.getDhListByProjectId(it.getStNumber(), it.getProjectId());
                    if (PlatformObjectUtils.isNotEmpty(dhListByProjectId)) {
                        dhList.add(dhListByProjectId);
                    }
                });
                resultVo.setSdList(sdList);
                resultVo.setDhList(dhList);
                resultVo.setPfEntity(pfEntity);
            }
        }
        return resultVo;
    }

    private double getEswvValue(List<JcRfcpY06> jcRfcpY06, double shearWaveVelocityValue) {
        //分层数
        int n = jcRfcpY06.size();
        double t = 0;
        for (int i = 0; i < n; i++) {
            t += jcRfcpY06.get(i).getLayerThickness() / jcRfcpY06.get(i).getShearWaveVelocity();
        }
        if (shearWaveVelocityValue > 20) {
            shearWaveVelocityValue = 20;
        }
        return shearWaveVelocityValue / t;
    }

    /**
     * 计算覆盖层厚度m
     *
     * @param jcRfcpY15
     * @return
     */
    private double getShearWaveVelocityValue(List<JcRfcpY15> jcRfcpY15) {
        List<JcRfcpY15> orderJcY15 = jcRfcpY15.stream()
                .sorted(Comparator.comparingInt(JcRfcpY15::getAssiseNumber))
                .collect(Collectors.toList());

        int maxLayerNo = 0; // 最后一个满足条件的土层序号
        double coverThickness = 0; // 覆盖层厚度累加值

        for (JcRfcpY15 rfcpY15 : orderJcY15) {
            if (rfcpY15.getWaveVelocity() > 500) {
                boolean hasLowerVelocities = false;
                for (int i = rfcpY15.getAssiseNumber() + 1; i <= maxLayerNo; i++) {
                    JcRfcpY15 jc = orderJcY15.get(i - 1);
                    if (jc.getWaveVelocity() < 500) {
                        hasLowerVelocities = true;
                        break;
                    }
                }
                if (!hasLowerVelocities) {
                    maxLayerNo = rfcpY15.getAssiseNumber();
                    coverThickness += layerThickness(orderJcY15, maxLayerNo);
                }
            }
        }
        return coverThickness;
    }

    // 计算指定土层及以上土层的层厚累加值
    private static double layerThickness(List<JcRfcpY15> layers, int layerNo) {
        double thickness = 0;
        for (int i = 0; i < layerNo; i++) {
            thickness += layers.get(i).getWaveVelocity();
        }
        return thickness / 1000; // 转换为m单位
    }

    @Override
    public void exportData(DrillHoleQueryParam param, HttpServletResponse response) {
        try {
            List<DrillHoleQueryVo> data = drillHoleQueryRepository.getData(param);
            data.forEach(it->{
                if(StringUtils.isBlank(it.getFieldType())){
                 it.setFieldType("无");
                }
            });
            FileUtil.exportExcel(data, "钻孔信息", "钻孔信息", DrillHoleQueryVo.class, "钻孔信息", response);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }


    public void exportData1(DrillHoleQueryParam param, HttpServletResponse response) {
        try {
            //查询需要导出的数据
            List<DrillHoleQueryVo> data = drillHoleQueryRepository.getData(param);
            ArrayList<DzqhApCruxLayerPfEntity> pfList = new ArrayList<>();
            ArrayList<List<DzqhApCruxDhEntity>> dhList = new ArrayList<>();
            ArrayList<DzqhApCruxScEntity> scList = new ArrayList<>();
            ArrayList<List<DzqhApCruxSdEntity>> sdList = new ArrayList<>();


            data.forEach(it -> {
                DrillHoleVo dataById = getDataById(it.getProjectId(), it.getModel());
                DzqhApCruxLayerPfEntity pfEntity = dataById.getPfEntity();
                if (PlatformObjectUtils.isNotEmpty(pfEntity)) {
                    pfList.add(pfEntity);
                }

                List<DzqhApCruxDhEntity> dhDataList = dataById.getDhList();
                if (PlatformObjectUtils.isNotEmpty(dhDataList)) {
                    dhList.add(dhDataList);
                }

                DzqhApCruxScEntity scEntity = dataById.getScEntity();
                if (PlatformObjectUtils.isNotEmpty(scEntity)) {
                    scList.add(scEntity);
                }

                List<DzqhApCruxSdEntity> sdDataList = dataById.getSdList();
                if (PlatformObjectUtils.isNotEmpty(sdDataList)) {
                    sdList.add(sdDataList);
                }
            });

            ArrayList<DzqhApCruxDhEntity> dhDataList = new ArrayList<>();
            for (List<DzqhApCruxDhEntity> item : dhList) {
                if (item != null) {
                    dhDataList.addAll(item);
                }
            }

            ArrayList<DzqhApCruxSdEntity> sdDataList = new ArrayList<>();
            for (List<DzqhApCruxSdEntity> item : sdList) {
                if (item != null) {
                    sdDataList.addAll(item);
                }
            }

            HSSFWorkbook wb = new HSSFWorkbook();

            // 样式设置
            HSSFCellStyle style = wb.createCellStyle();
            style.setFillPattern(FillPatternType.NO_FILL); // 背景
            style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 背景色AQUA.getIndex()
            style.setBorderBottom(BorderStyle.THIN); // 下边框
            style.setBorderLeft(BorderStyle.THIN);// 左边框
            style.setBorderTop(BorderStyle.THIN);// 上边框
            style.setBorderRight(BorderStyle.THIN);// 右边框
            style.setAlignment(HorizontalAlignment.CENTER);//左右居中
            style.setVerticalAlignment(VerticalAlignment.BOTTOM);// 上下居中
            style.setWrapText(true);//自动换行


            //创建sheet1
            HSSFSheet sheet1 = wb.createSheet("成孔信息-导出");
            HSSFRow row1 = sheet1.createRow(0);
            String[] sheet1Title = {"序号", "钻孔依托的项目", "钻孔编号", "钻孔位置-经度", "钻孔位置-纬度", "钻孔深度", "地面高程", "地下水位"};
            for (int i = 0; i < sheet1Title.length; i++) {
                Cell cell = row1.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet1Title[i]);
                sheet1.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet2
            HSSFSheet sheet2 = wb.createSheet("土动力参数-导出");
            HSSFRow row2 = sheet2.createRow(0);
            String[] sheet2Title = {"序号", "土类号", "岩土性名称", "钻孔编号", "土样埋深", "参数来源", "密度(kg/m3)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.05)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.10)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.50)", "模量比(G/Gmax)剪应变(γ)（10^-4×1.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×5.00)",
                    "模量比(G/Gmax)剪应变(γ)（10^-4×10.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×50.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×100.00)", "阻尼比(λ)剪应变(γ)（10^-4×0.05)", "阻尼比(λ)剪应变(γ)（10^-4×0.10)", "阻尼比(λ)剪应变(γ)（10^-4×0.50)", "阻尼比(λ)剪应变(γ)（10^-4×1.00)", "阻尼比(λ)剪应变(γ)（10^-4×5.00)", "阻尼比(λ)剪应变(γ)（10^-4×10.00)",
                    "阻尼比(λ)剪应变(γ)（10^-4×50.00)", "阻尼比(λ)剪应变(γ)（10^-4×100.00)"};
            for (int i = 0; i < sheet2Title.length; i++) {
                Cell cell = row2.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet2Title[i]);
                cell.setCellValue(sheet2Title[i]);
                cell.setCellValue(sheet2Title[i]);
                sheet2.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet3
            HSSFSheet sheet3 = wb.createSheet("钻孔计算模型-导出");
            HSSFRow row3 = sheet3.createRow(0);
            String[] sheet3Title = {"序号", "岩土性名称", "土类号", "层底深度", "密度", "层厚", "剪切波波速"};
            for (int i = 0; i < sheet3Title.length; i++) {
                Cell cell = row3.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet3Title[i]);
                sheet3.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet4
            HSSFSheet sheet4 = wb.createSheet("场地类别判别信息表-导出");
            HSSFRow row4 = sheet4.createRow(0);
            String[] sheet4Title = {"序号", "钻孔编号", "20m等效剪切波速（M/s）", "覆盖层厚度m", "场地类别"};
            for (int i = 0; i < sheet4Title.length; i++) {
                Cell cell = row4.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet4Title[i]);
                sheet4.setColumnWidth(i, 10000);   //设置列宽
            }


            if (pfList.size() > 0) {
                for (int i = 0; i < pfList.size(); i++) {
                    DzqhApCruxLayerPfEntity pfEntity = pfList.get(i);
                    //设置 sheet1 中的值
                    row1 = sheet1.createRow(sheet1.getLastRowNum() + 1);
                    row1.createCell(0).setCellValue(i + 1);

                    row1.createCell(1).setCellValue(pfEntity.getProjectName());
                    row1.createCell(2).setCellValue(pfEntity.getBoreholeNumber());
                    row1.createCell(3).setCellValue(pfEntity.getHlLongitude());
                    row1.createCell(4).setCellValue(pfEntity.getHlLatitude());
                    row1.createCell(5).setCellValue(pfEntity.getDrillingDepth());
                    row1.createCell(6).setCellValue(pfEntity.getGroundElevation());
                    row1.createCell(7).setCellValue(pfEntity.getGroundwaterLevel());
                }
            }

            //设置 sheet2 中的值
            if (sdDataList.size() > 0) {
                for (int i = 0; i < sdDataList.size(); i++) {
                    DzqhApCruxSdEntity sdEntity = sdDataList.get(i);
                    row2 = sheet2.createRow(sheet2.getLastRowNum() + 1);
                    row2.createCell(0).setCellValue(i + 1);
                    row2.createCell(1).setCellValue(sdEntity.getStNumber());
                    row2.createCell(2).setCellValue(sdEntity.getGeotechnicalName());
                    row2.createCell(3).setCellValue(sdEntity.getBoreholeNumber());
                    row2.createCell(4).setCellValue(sdEntity.getBdosSample());
                    row2.createCell(5).setCellValue(sdEntity.getParameterSource());
                    row2.createCell(6).setCellValue(sdEntity.getSdDensity());
                    if (sdEntity.getModulusRatio1() != null) {
                        row2.createCell(7).setCellValue(sdEntity.getModulusRatio1());
                    }
                    if (sdEntity.getModulusRatio2() != null) {
                        row2.createCell(8).setCellValue(sdEntity.getModulusRatio2());
                    }
                    if (sdEntity.getModulusRatio3() != null) {
                        row2.createCell(9).setCellValue(sdEntity.getModulusRatio3());
                    }
                    if (sdEntity.getModulusRatio4() != null) {
                        row2.createCell(10).setCellValue(sdEntity.getModulusRatio4());
                    }
                    if (sdEntity.getModulusRatio5() != null) {
                        row2.createCell(11).setCellValue(sdEntity.getModulusRatio5());
                    }
                    if (sdEntity.getModulusRatio6() != null) {
                        row2.createCell(12).setCellValue(sdEntity.getModulusRatio6());
                    }
                    if (sdEntity.getModulusRatio7() != null) {
                        row2.createCell(13).setCellValue(sdEntity.getModulusRatio7());
                    }
                    if (sdEntity.getModulusRatio8() != null) {
                        row2.createCell(14).setCellValue(sdEntity.getModulusRatio8());
                    }
                    if (sdEntity.getDampingRatio1() != null) {
                        row2.createCell(15).setCellValue(sdEntity.getDampingRatio1());
                    }
                    if (sdEntity.getDampingRatio2() != null) {
                        row2.createCell(16).setCellValue(sdEntity.getDampingRatio2());
                    }
                    if (sdEntity.getDampingRatio3() != null) {
                        row2.createCell(17).setCellValue(sdEntity.getDampingRatio3());
                    }
                    if (sdEntity.getDampingRatio4() != null) {
                        row2.createCell(18).setCellValue(sdEntity.getDampingRatio4());
                    }
                    if (sdEntity.getDampingRatio5() != null) {
                        row2.createCell(19).setCellValue(sdEntity.getDampingRatio5());
                    }
                    if (sdEntity.getDampingRatio6() != null) {
                        row2.createCell(20).setCellValue(sdEntity.getDampingRatio6());
                    }
                    if (sdEntity.getDampingRatio7() != null) {
                        row2.createCell(21).setCellValue(sdEntity.getDampingRatio7());
                    }
                    if (sdEntity.getDampingRatio8() != null) {
                        row2.createCell(22).setCellValue(sdEntity.getDampingRatio8());
                    }
                }
            }

            //设置 sheet3 中的值
            if (dhDataList.size() > 0) {
                for (int i = 0; i < dhDataList.size(); i++) {
                    DzqhApCruxDhEntity dhEntity = dhDataList.get(i);
                    row3 = sheet3.createRow(sheet3.getLastRowNum() + 1);
                    row3.createCell(0).setCellValue(i + 1);
                    row3.createCell(1).setCellValue(dhEntity.getGeotechnicalName());
                    row3.createCell(2).setCellValue(dhEntity.getStNumber());
                    row3.createCell(3).setCellValue(dhEntity.getLbDepth());
                    row3.createCell(4).setCellValue(dhEntity.getLayerThickness());
                    row3.createCell(5).setCellValue(dhEntity.getGeotechnicalDensity());
                    row3.createCell(6).setCellValue(dhEntity.getSwVelocity());
                }
            }

            //设置 sheet4 中的值
            if (scList.size() > 0) {
                for (int i = 0; i < scList.size(); i++) {
                    DzqhApCruxScEntity scEntity = scList.get(i);
                    row4 = sheet4.createRow(sheet4.getLastRowNum() + 1);
                    row4.createCell(0).setCellValue(i + 1);
                    row4.createCell(1).setCellValue(scEntity.getBoreholeNumber());
                    if (scEntity.getEswv() != null) {
                        row4.createCell(2).setCellValue(scEntity.getEswv());
                    }
                    if (scEntity.getTocLayer() != null) {
                        row4.createCell(3).setCellValue(scEntity.getTocLayer());
                    }
                }
            }

            String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            String name = dateStr + "钻孔信息.xls";
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
            response.setHeader("Content-Disposition", "attachment;fileName="
                    + new String(name.getBytes("GB2312"), "ISO8859-1"));
            response.setCharacterEncoding("UTF-8");

            OutputStream out = response.getOutputStream();
            wb.write(out);
            if (out != null) {
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void exportDetails(String id, String type, HttpServletResponse response) {
        try {
            //查询需要导出的数据
            DrillHoleVo dataById = getDataById(id, type);

            HSSFWorkbook wb = new HSSFWorkbook();

//            // 样式设置
            HSSFCellStyle style = wb.createCellStyle();

            //创建工作簿对象
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFCellStyle cellStyle = workbook.createCellStyle();
            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            cellStyle.setAlignment(HorizontalAlignment.CENTER);


            //创建sheet1
            HSSFSheet sheet1 = wb.createSheet("成孔信息-导出");
            HSSFRow row1 = sheet1.createRow(0);
            String[] sheet1Title = {"序号", "钻孔依托的项目", "钻孔编号", "钻孔位置-经度(°)", "钻孔位置-纬度(°)", "钻孔深度(m)", "地面高程(m)", "地下水位(m)"};
            for (int i = 0; i < sheet1Title.length; i++) {
                Cell cell = row1.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet1Title[i]);
            }

            //创建sheet2
            HSSFSheet sheet2 = wb.createSheet("土动力参数-导出");
            HSSFRow row2 = sheet2.createRow(0);
            String[] sheet2Title = {"序号", "土类号", "岩土性名称", "钻孔编号", "土样埋深", "参数来源", "密度(kg/m3)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.05)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.10)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.50)", "模量比(G/Gmax)剪应变(γ)（10^-4×1.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×5.00)",
                    "模量比(G/Gmax)剪应变(γ)（10^-4×10.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×50.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×100.00)", "阻尼比(λ)剪应变(γ)（10^-4×0.05)", "阻尼比(λ)剪应变(γ)（10^-4×0.10)", "阻尼比(λ)剪应变(γ)（10^-4×0.50)", "阻尼比(λ)剪应变(γ)（10^-4×1.00)", "阻尼比(λ)剪应变(γ)（10^-4×5.00)", "阻尼比(λ)剪应变(γ)（10^-4×10.00)",
                    "阻尼比(λ)剪应变(γ)（10^-4×50.00)", "阻尼比(λ)剪应变(γ)（10^-4×100.00)"};
            for (int i = 0; i < sheet2Title.length; i++) {
                Cell cell = row2.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet2Title[i]);
                cell.setCellValue(sheet2Title[i]);
                cell.setCellValue(sheet2Title[i]);
            }

            //创建sheet3
            HSSFSheet sheet3 = wb.createSheet("钻孔计算模型-导出");
            HSSFRow row3 = sheet3.createRow(0);
            String[] sheet3Title = {"序号", "岩土性名称", "土类号", "层底深度(m)", "密度(kg/m3)", "层厚(m)", "剪切波波速V(m/s)"};
            for (int i = 0; i < sheet3Title.length; i++) {
                Cell cell = row3.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet3Title[i]);
            }

            //创建sheet4
            HSSFSheet sheet4 = wb.createSheet("场地类别判别信息表-导出");
            HSSFRow row4 = sheet4.createRow(0);
            String[] sheet4Title = {"序号", "钻孔编号", "20m等效剪切波速（M/s）", "覆盖层厚度m", "场地类别"};
            for (int i = 0; i < sheet4Title.length; i++) {
                Cell cell = row4.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet4Title[i]);
            }


            if (PlatformObjectUtils.isNotEmpty(dataById.getPfEntity())) {
                DzqhApCruxLayerPfEntity pfEntity = dataById.getPfEntity();
                //设置 sheet1 中的值
                row1 = sheet1.createRow(sheet1.getLastRowNum() + 1);
                row1.createCell(0).setCellValue(1);
                row1.createCell(1).setCellValue(pfEntity.getProjectName());
                row1.createCell(2).setCellValue(pfEntity.getBoreholeNumber());
                row1.createCell(3).setCellValue(pfEntity.getHlLongitude());
                row1.createCell(4).setCellValue(pfEntity.getHlLatitude());
                row1.createCell(5).setCellValue(pfEntity.getDrillingDepth());
                row1.createCell(6).setCellValue(pfEntity.getGroundElevation());
                row1.createCell(7).setCellValue(pfEntity.getGroundwaterLevel());
            }

            //设置 sheet2 中的值
            List<DzqhApCruxSdEntity> sdList = dataById.getSdList();
            if (sdList.size() > 0) {
                for (int i = 0; i < sdList.size(); i++) {
                    DzqhApCruxSdEntity sdEntity = sdList.get(i);
                    row2 = sheet2.createRow(sheet2.getLastRowNum() + 1);
                    row2.createCell(0).setCellValue(i + 1);
                    row2.createCell(1).setCellValue(sdEntity.getStNumber());
                    row2.createCell(2).setCellValue(sdEntity.getGeotechnicalName());
                    row2.createCell(3).setCellValue(sdEntity.getBoreholeNumber());
                    row2.createCell(4).setCellValue(sdEntity.getBdosSample());
                    row2.createCell(5).setCellValue(sdEntity.getParameterSource());
                    row2.createCell(6).setCellValue(sdEntity.getSdDensity());
                    if (sdEntity.getModulusRatio1() != null) {
                        row2.createCell(7).setCellValue(sdEntity.getModulusRatio1());
                    }
                    if (sdEntity.getModulusRatio2() != null) {
                        row2.createCell(8).setCellValue(sdEntity.getModulusRatio2());
                    }
                    if (sdEntity.getModulusRatio3() != null) {
                        row2.createCell(9).setCellValue(sdEntity.getModulusRatio3());
                    }
                    if (sdEntity.getModulusRatio4() != null) {
                        row2.createCell(10).setCellValue(sdEntity.getModulusRatio4());
                    }
                    if (sdEntity.getModulusRatio5() != null) {
                        row2.createCell(11).setCellValue(sdEntity.getModulusRatio5());
                    }
                    if (sdEntity.getModulusRatio6() != null) {
                        row2.createCell(12).setCellValue(sdEntity.getModulusRatio6());
                    }
                    if (sdEntity.getModulusRatio7() != null) {
                        row2.createCell(13).setCellValue(sdEntity.getModulusRatio7());
                    }
                    if (sdEntity.getModulusRatio8() != null) {
                        row2.createCell(14).setCellValue(sdEntity.getModulusRatio8());
                    }
                    if (sdEntity.getDampingRatio1() != null) {
                        row2.createCell(15).setCellValue(sdEntity.getDampingRatio1());
                    }
                    if (sdEntity.getDampingRatio2() != null) {
                        row2.createCell(16).setCellValue(sdEntity.getDampingRatio2());
                    }
                    if (sdEntity.getDampingRatio3() != null) {
                        row2.createCell(17).setCellValue(sdEntity.getDampingRatio3());
                    }
                    if (sdEntity.getDampingRatio4() != null) {
                        row2.createCell(18).setCellValue(sdEntity.getDampingRatio4());
                    }
                    if (sdEntity.getDampingRatio5() != null) {
                        row2.createCell(19).setCellValue(sdEntity.getDampingRatio5());
                    }
                    if (sdEntity.getDampingRatio6() != null) {
                        row2.createCell(20).setCellValue(sdEntity.getDampingRatio6());
                    }
                    if (sdEntity.getDampingRatio7() != null) {
                        row2.createCell(21).setCellValue(sdEntity.getDampingRatio7());
                    }
                    if (sdEntity.getDampingRatio8() != null) {
                        row2.createCell(22).setCellValue(sdEntity.getDampingRatio8());
                    }
                }
            }

            //设置 sheet3 中的值
            List<DzqhApCruxDhEntity> dhList = dataById.getDhList();
            if (dhList.size() > 0) {
                for (int i = 0; i < dhList.size(); i++) {
                    DzqhApCruxDhEntity dhEntity = dhList.get(i);
                    row3 = sheet3.createRow(sheet3.getLastRowNum() + 1);
                    row3.createCell(0).setCellValue(i + 1);
                    row3.createCell(1).setCellValue(dhEntity.getGeotechnicalName());
                    row3.createCell(2).setCellValue(dhEntity.getStNumber());
                    row3.createCell(3).setCellValue(dhEntity.getLbDepth());
                    row3.createCell(4).setCellValue(dhEntity.getGeotechnicalDensity());
                    row3.createCell(5).setCellValue(dhEntity.getLayerThickness());
                    row3.createCell(6).setCellValue(dhEntity.getSwVelocity());
                }
            }

            //设置 sheet4 中的值
            if (PlatformObjectUtils.isNotEmpty(dataById.getScEntity())) {
                DzqhApCruxScEntity scEntity = dataById.getScEntity();
                row4 = sheet4.createRow(sheet4.getLastRowNum() + 1);
                row4.createCell(0).setCellValue(1);
                row4.createCell(1).setCellValue(scEntity.getBoreholeNumber());
                if (scEntity.getEswv() != null) {
                    row4.createCell(2).setCellValue(scEntity.getEswv());
                }
                if (scEntity.getTocLayer() != null) {
                    row4.createCell(3).setCellValue(scEntity.getTocLayer());
                }
                if (scEntity.getFieldType() != null) {
                    row4.createCell(4).setCellValue(scEntity.getFieldType());
//                    switch (scEntity.getFieldType()) {
//                        case "1":
//                            row4.createCell(4).setCellValue("Ⅰ1");
//                            break;
//                        case "2":
//                            row4.createCell(4).setCellValue("Ⅱ");
//                            break;
//                        case "3":
//                            row4.createCell(4).setCellValue("Ⅲ");
//                            break;
//                        case "4":
//                            row4.createCell(4).setCellValue("Ⅳ");
//                            break;
//                        case "10":
//                            row4.createCell(4).setCellValue("Ⅰ0");
//                            break;
//                    }
                }
            }

            String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            String name = dateStr + "钻孔信息.xls";
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
            response.setHeader("Content-Disposition", "attachment;fileName="
                    + new String(name.getBytes("GB2312"), "ISO8859-1"));
            response.setCharacterEncoding("UTF-8");

            OutputStream out = response.getOutputStream();
            wb.write(out);
            if (out != null) {
                out.flush();
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public RestResponse uploadDetails(MultipartFile file) {
        try {
            ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
            List<Object> title = reader.readRow(1);
            String titleName = "[钻孔依托的项目, 钻孔编号, 孔位经度（°）, 孔位纬度（°）, 钻孔深度（m）, 地面高程（m）, 地下水位（m）, 序号, 土类号, 岩土性名称, 钻孔编号, 土样埋深(米), 参数来源, 密度(kg/m^3), 模量比(G/Gmax)剪应变(γ)（10-4×0.05), 模量比(G/Gmax)剪应变(γ)（10-4×0.10), 模量比(G/Gmax)剪应变(γ)（10-4×0.50), 模量比(G/Gmax)剪应变(γ)（10-4×1.00), 模量比(G/Gmax)剪应变(γ)（10-4×5.00), 模量比(G/Gmax)剪应变(γ)（10-4×10.00), 模量比(G/Gmax)剪应变(γ)（10-4×50.00), 模量比(G/Gmax)剪应变(γ)（10-4×100.00), 阻尼比(λ)剪应变(γ)（10-4×0.05), 阻尼比(λ)剪应变(γ)（10-4×0.10), 阻尼比(λ)剪应变(γ)（10-4×0.50), 阻尼比(λ)剪应变(γ)（10-4×1.00), 阻尼比(λ)剪应变(γ)（10-4×5.00), 阻尼比(λ)剪应变(γ)（10-4×10.00), 阻尼比(λ)剪应变(γ)（10-4×50.00), 阻尼比(λ)剪应变(γ)（10-4×100.00), 序号, 岩土性名称, 土类号, 层底深度 (m), 密度(kg/m^3), 层厚(m), 剪切波波速V(m/s), 序号, 钻孔编号, 20m等效剪切波速（M/s）, 覆盖层厚度m, 场地类别]";
            if (!titleName.equals(title.toString())) {
                return RestResponse.fail("导入失败，请检查表头是否改动");
            }
            List<List<Object>> read = reader.read(2, reader.getRowCount());
            if (read.size() == 0) {
                return RestResponse.fail("导入失败，表格中无数据");
            }
            //数据校验
            RestResponse rs = detailsVerification(read.size(), read);
            if (rs.getCode() != 200) {
                return RestResponse.fail(rs.getMessage());
            }
            ArrayList<DzqhApCruxLayerPfEntity> pfList = new ArrayList<>();
            ArrayList<DzqhApCruxScEntity> scList = new ArrayList<>();
            ArrayList<DzqhApCruxSdEntity> sdList = new ArrayList<>();
            ArrayList<DzqhApCruxDhEntity> dhList = new ArrayList<>();
            ArrayList<DzqhApAsicMapEntity> mapList = new ArrayList<>();
            for (List<Object> objects : read) {
                List<DzqhApAsicMapEntity> mapEntities = saResultsRepository.queryProjectByProjectName(objects.get(0).toString());
                if (mapEntities.size() != 0) {
                    return RestResponse.fail("项目名称已存在");
                }
                String uuid = UUIDGenerator.getUUID();
                DzqhApAsicMapEntity mapEntity = new DzqhApAsicMapEntity();
                mapEntity.setProjectId(uuid);
                mapEntity.setCreateUser(PlatformSessionContext.getUserID());
                mapEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                mapEntity.setIsDelete(YNEnum.N.toString());
                mapEntity.setModel("风险普查成果库");
                mapEntity.setProjectName(objects.get(0).toString());
                mapList.add(mapEntity);

                DzqhApCruxLayerPfEntity pfEntity = new DzqhApCruxLayerPfEntity();
                pfEntity.setPfId(UUIDGenerator.getUUID());
                pfEntity.setProjectId(uuid);
                pfEntity.setProjectName(objects.get(0).toString());
                pfEntity.setBoreholeNumber(objects.get(1).toString());
                pfEntity.setHlLongitude(objects.get(2).toString());
                pfEntity.setHlLatitude(objects.get(3).toString());
                pfEntity.setDrillingDepth(Double.valueOf(objects.get(4).toString()));
                pfEntity.setGroundElevation(Double.valueOf(objects.get(5).toString()));
                pfEntity.setGroundwaterLevel(Double.valueOf(objects.get(6).toString()));
                pfEntity.setCreateUser(PlatformSessionContext.getUserID());
                pfEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pfEntity.setIsDelete(YNEnum.N.toString());
                pfList.add(pfEntity);

                DzqhApCruxSdEntity sdEntity = new DzqhApCruxSdEntity();
                sdEntity.setSdId(UUIDGenerator.getUUID());
                sdEntity.setProjectId(uuid);
                sdEntity.setStNumber(objects.get(8).toString());
                sdEntity.setGeotechnicalName(objects.get(9).toString());
                sdEntity.setBoreholeNumber(objects.get(10).toString());
                sdEntity.setBdosSample(objects.get(11).toString());
                sdEntity.setParameterSource(objects.get(12).toString());
                sdEntity.setSdDensity(objects.get(13).toString());
                sdEntity.setModulusRatio1(Double.valueOf(objects.get(14).toString()));
                sdEntity.setModulusRatio2(Double.valueOf(objects.get(15).toString()));
                sdEntity.setModulusRatio3(Double.valueOf(objects.get(16).toString()));
                sdEntity.setModulusRatio4(Double.valueOf(objects.get(17).toString()));
                sdEntity.setModulusRatio5(Double.valueOf(objects.get(18).toString()));
                sdEntity.setModulusRatio6(Double.valueOf(objects.get(19).toString()));
                sdEntity.setModulusRatio7(Double.valueOf(objects.get(20).toString()));
                sdEntity.setModulusRatio8(Double.valueOf(objects.get(21).toString()));
                sdEntity.setDampingRatio1(Double.valueOf(objects.get(22).toString()));
                sdEntity.setDampingRatio2(Double.valueOf(objects.get(23).toString()));
                sdEntity.setDampingRatio3(Double.valueOf(objects.get(24).toString()));
                sdEntity.setDampingRatio4(Double.valueOf(objects.get(25).toString()));
                sdEntity.setDampingRatio5(Double.valueOf(objects.get(26).toString()));
                sdEntity.setDampingRatio6(Double.valueOf(objects.get(27).toString()));
                sdEntity.setDampingRatio7(Double.valueOf(objects.get(28).toString()));
                sdEntity.setDampingRatio8(Double.valueOf(objects.get(29).toString()));
                sdList.add(sdEntity);

                DzqhApCruxDhEntity dhEntity = new DzqhApCruxDhEntity();
                dhEntity.setProjectId(uuid);
                dhEntity.setGeotechnicalId(UUIDGenerator.getUUID());
                dhEntity.setGeotechnicalName(objects.get(31).toString());
                dhEntity.setStNumber(objects.get(32).toString());
                dhEntity.setLbDepth(Double.valueOf(objects.get(33).toString()));
                dhEntity.setGeotechnicalDensity(Double.valueOf(objects.get(34).toString()));
                dhEntity.setLayerThickness(Double.valueOf(objects.get(35).toString()));
                dhEntity.setSwVelocity(Double.valueOf(objects.get(36).toString()));
                dhList.add(dhEntity);

                DzqhApCruxScEntity scEntity = new DzqhApCruxScEntity();
                scEntity.setScDistinguishId(UUIDGenerator.getUUID());
                scEntity.setProjectId(uuid);
                scEntity.setBoreholeNumber(objects.get(38).toString());
                scEntity.setEswv(Double.valueOf(objects.get(39).toString()));
                scEntity.setTocLayer(Double.valueOf(objects.get(40).toString()));
                scEntity.setFieldType(getFileType(objects.get(41).toString()));
                scList.add(scEntity);
            }
            mapList.forEach(it -> {
                saResultsRepository.saveApAsicMap(it);
            });
            pfList.forEach(it -> {
                saResultsRepository.saveApCruxLayerPf(it);
            });
            sdList.forEach(it -> {
                saResultsRepository.saveApCruxSd(it);
            });
            dhList.forEach(it -> {
                saResultsRepository.saveApCruxDh(it);
            });
            scList.forEach(it -> {
                saResultsRepository.saveApCruxSc(it);
            });
            return RestResponse.succeed("导入成功!");
        } catch (IOException e) {
            String message = "导入失败!";
            log.error(message, e);
            return RestResponse.fail(message);
        }
    }


    private String getFileType(String type) {
        String resultType = "";
        switch (type) {
            case "Ⅰ1":
                resultType = "1";
                break;
            case "Ⅱ":
                resultType = "2";
                break;
            case "Ⅲ":
                resultType = "3";
                break;
            case "Ⅳ":
                resultType = "4";
                break;
            case "Ⅰ0":
                resultType = "10";
                break;
        }
        return resultType;
    }

    private RestResponse detailsVerification(int size, List<List<Object>> data) {
        for (int i = 0; i < size; i++) {
            List<Object> objects = data.get(i);
            if (StringUtils.isBlank(objects.get(0).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{钻孔依托的项目}不能为空！");
            if (StringUtils.isBlank(objects.get(1).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{钻孔编号}不能为空！");
            if (StringUtils.isBlank(objects.get(2).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{孔位经度（°）}不能为空！");
            if (StringUtils.isBlank(objects.get(3).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{孔位纬度（°）}不能为空！");
            if (StringUtils.isBlank(objects.get(4).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{钻孔深度（m）}不能为空！");
            if (StringUtils.isBlank(objects.get(5).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{地面高程（m）}不能为空！");
            if (StringUtils.isBlank(objects.get(6).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{地下水位（m）}不能为空！");
            if (StringUtils.isBlank(objects.get(8).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{土类号}不能为空！");
            if (StringUtils.isBlank(objects.get(9).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{岩土性名称}不能为空！");
            if (StringUtils.isBlank(objects.get(10).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{钻孔编号}不能为空！");
            if (StringUtils.isBlank(objects.get(11).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{土样埋深}不能为空！");
            if (StringUtils.isBlank(objects.get(12).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{参数来源}不能为空！");
            if (StringUtils.isBlank(objects.get(13).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{密度}不能为空！");
            if (StringUtils.isBlank(objects.get(14).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×0.05)}不能为空！");
            if (StringUtils.isBlank(objects.get(15).toString()))
                return RestResponse.fail("第" + (i + 3) + "模量比(G/Gmax)剪应变(γ)（10-4×0.10)");
            if (StringUtils.isBlank(objects.get(16).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×0.50)}不能为空！");
            if (StringUtils.isBlank(objects.get(17).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×1.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(18).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×5.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(19).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×10.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(20).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×50.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(21).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{模量比(G/Gmax)剪应变(γ)（10-4×100.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(22).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×0.05)}不能为空！");
            if (StringUtils.isBlank(objects.get(23).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×0.10)}不能为空！");
            if (StringUtils.isBlank(objects.get(24).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×0.50)}不能为空！");
            if (StringUtils.isBlank(objects.get(25).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×1.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(26).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×5.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(27).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×10.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(28).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×50.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(29).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{阻尼比(λ)剪应变(γ)（10-4×100.00)}不能为空！");
            if (StringUtils.isBlank(objects.get(31).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{岩土性名称}不能为空！");
            if (StringUtils.isBlank(objects.get(32).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{土类号}不能为空！");
            if (StringUtils.isBlank(objects.get(33).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层底深度 (m)}不能为空！");
            if (StringUtils.isBlank(objects.get(34).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{密度(kg/m^3)}不能为空！");
            if (StringUtils.isBlank(objects.get(35).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{层厚(m)}不能为空！");
            if (StringUtils.isBlank(objects.get(36).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{剪切波波速V(m/s)}不能为空！");
            if (StringUtils.isBlank(objects.get(38).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{钻孔编号}不能为空！");
            if (StringUtils.isBlank(objects.get(39).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{20m等效剪切波速（M/s）}不能为空！");
            if (StringUtils.isBlank(objects.get(40).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{覆盖层厚度m}不能为空！");
            if (StringUtils.isBlank(objects.get(41).toString()))
                return RestResponse.fail("第" + (i + 3) + "行的{场地类别}不能为空！");
        }
        return RestResponse.succeed();
    }

    @Override
    public RestResponse getByGeom(DrillHoleQueryParam param,String geom) {
        String role = roleService.getRoleByUserId(PlatformSessionContext.getUserID());
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
        ArrayList<String> roleList = new ArrayList<>();
        for (Map roleMap : roleMaps) {
            String roleCode = (String) roleMap.get("roleCode");
            roleList.add(roleCode);
        }
        return RestResponse.succeed(drillHoleQueryRepository.getByGeom(param,roleList,geom));
    }

    @Override
    public RestResponse getListByGeom(String geom,HttpServletRequest request) {
        int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        String role = roleService.getRoleByUserId(PlatformSessionContext.getUserID());
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
        ArrayList<String> roleList = new ArrayList<>();
        for (Map roleMap : roleMaps) {
            String roleCode = (String) roleMap.get("roleCode");
            roleList.add(roleCode);
        }
        return RestResponse.succeed(drillHoleQueryRepository.getListByGeom(geom,page, size,roleList));
    }
}
